﻿Imports Mystery

<GlobalAvalibleObject()>
Public Interface IStartNavigator

    ''' <summary>
    ''' return the what to diplay in the default start control of 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function getMostImportantButtons() As IEnumerable(Of IButton)

    Function getAlltheButtons() As IEnumerable(Of IButton)

    Function getNewContentButtons() As IEnumerable(Of IButton)

    Function getAdditionalMenuItems() As IEnumerable(Of MenuItem)

End Interface

<GlobalAvalibleObjectImplementation(implementation_of:=GetType(IStartNavigator), overrides_exsisting:=False, singleton:=True)>
Public Class DefaultStartNavigator
    Implements IStartNavigator


    Private _all As IEnumerable(Of IButton)
    Private _important As IEnumerable(Of IButton)
    Private _add_buttons As IEnumerable(Of IButton)

    Private Const important_cout As Integer = 10

    Public Sub New()

        'content view
        Dim types As New List(Of Type)(getMystery().AssemblyRegister.getTypesMarkedWith(Of ContentTypeButtonAttribute)())
        Dim buttons As New List(Of IButton)
        Dim important As New List(Of IButton)
        For Each t As Type In types
            Dim attr As ContentTypeButtonAttribute = t.getMysteryAttribute(Of ContentTypeButtonAttribute)()
            Dim button As IButton = Activator.CreateInstance(attr.implementing_type)
            button.getText()
            buttons.Add(button)
            If attr.should_be_main AndAlso important.Count < important_cout Then
                important.Add(button)
            End If
        Next
        _all = buttons
        _important = important

        'content add
        types = New List(Of Type)(getMystery().AssemblyRegister.getTypesMarkedWith(Of ContentButtonAddAttribute)())
        buttons = New List(Of IButton)
        For Each t As Type In types
            Dim attr As ContentButtonAddAttribute = getMystery().AssemblyRegister.getMysteryClassAttribute(Of ContentButtonAddAttribute)(t)
            Dim button As IButton = attr.createButton()
            buttons.Add(button)
        Next
        _add_buttons = buttons
    End Sub

    Public Function getAlltheButtons() As System.Collections.Generic.IEnumerable(Of IButton) Implements IStartNavigator.getAlltheButtons
        Return _all
    End Function

    Public Function getMostImportantButtons() As System.Collections.Generic.IEnumerable(Of IButton) Implements IStartNavigator.getMostImportantButtons
        Return _important
    End Function

    Public Function getNewContentButtons() As System.Collections.Generic.IEnumerable(Of IButton) Implements IStartNavigator.getNewContentButtons
        Return _add_buttons
    End Function

    Public Function getAdditionalMenuItemes() As System.Collections.Generic.IEnumerable(Of System.Windows.Controls.MenuItem) Implements IStartNavigator.getAdditionalMenuItems
        Return New List(Of MenuItem)
    End Function
End Class
